(deffacts ini
(letra 1 c)
(letra 2 a)
(letra 3 c)
(letra 4 b)
(letra 5 a)
(letra 6 b) )

;; cacbab -> cacabb -> accabb -> acacbb -> aaccbb -> aacbcb -> aabccb -> aabcbc -> aabbcc

(defrule r1
	?h1<-(letra ?i b)
	?h2<-(letra ?j a)
	(test (eq ?i (- ?j 1)))
	=>
	(retract ?h1)
	(retract ?h2)
	(assert (letra ?i a))
	(assert (letra ?j b))
)

(defrule r2
	?h1<-(letra ?i c)
	?h2<-(letra ?j a) 
	(test (eq ?i (- ?j 1)))
	=> 
	(retract ?h1)
	(retract ?h2)
	(assert (letra ?i a))
	(assert (letra ?j c))
)

(defrule r3
	?h1<-(letra ?i c)
	?h2<-(letra ?j b)
	(test (eq ?i (- ?j 1)))
	=>
	(retract ?h1)
	(retract ?h2)
	(assert (letra ?i b))
	(assert (letra ?j c))
)

/*--------- asi ejecuta el archivo al cargarlo con "batch" en el interprete --*/
(reset)
(run)
